// 页面路径：store/index.js
import Vue from "vue";
import Vuex from "vuex";
//vuex 持久化插件
import createPersistedState from "vuex-persistedstate";
import user from "@/store/modules/user";
import goods from "@/store/modules/goods";
Vue.use(Vuex); //vue的插件机制

export default new Vuex.Store({
  plugins: [
    createPersistedState({
      // 指定需要持久化的模块
      paths: [
        "user.userInfo",
        "user.token",
        "user.identityList",
        "user.currentIdentity",
      ],
      storage: {
        getItem: (key) => uni.getStorageSync(key),
        setItem: (key, value) => uni.setStorageSync(key, value),
        removeItem: (key) => uni.removeStorageSync(key),
      },
    }),
  ],
  modules: {
    user,
    goods,
  },
});
